package com.itheima.controller;

import com.itheima.domain.Book;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

@Controller
public class DemoController {

    @RequestMapping("/test1")
    //使用postman便于测试body-->raw-->选择Json,传递{"name":"java编程思想","price":40.00}
    //@RequestBody  处理请求数据 使用这个注解可以把请求的Json转为对象
    public String test1(@RequestBody() Book book) {
        System.out.println(book);
        return "page";
    }

    //http://localhost/test2/66/man?name=zhangsan&age=23
    @RequestMapping("/test2/{price}/{gender}")
    @ResponseBody
    public Book test2(@PathVariable() Double price,
                      @PathVariable() String gender,
                      @RequestParam String name,
                      @RequestParam Integer age) {
        System.out.println(price + ", " + gender + ", " + name + ", " + age);
        Book book = new Book();
        book.setName(name);
        book.setPrice(price);
        return book;
    }


}
